/*
 * $Id: ThfProperties.java,v 1.4 2010/02/24 20:45:18 afaichun Exp $
 * 
 * Copyright (C) 2008 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.iptds.transaction;

import java.util.Properties;

import com.ge.healthcare.autosc.common.ASCUtil;
/**
 * 
 * @author 212042946
 *
 */
public class ThfProperties extends Properties implements Comparable<Properties>{

	public static final long serialVersionUID = 0L;

	public String getTdfName() {
		return getProperty("TDFNAME");
	}
	
	public String getTransId() {
		return getProperty("TRANSID");
	}
	
	public String getServiceId() {
		return getProperty("SERVICEID");
	}

	public String getCreatedBy() {
		return getProperty("CREATEDBY");
	}
	
	public String getTdfFormat() {
		return getProperty("TDFFORMAT");
	}
	
	public String getSdfnr() {
		return getProperty("SDFNR");
	}
	
	public String getTdfSize() {
		return getProperty("TDFSIZE");
	}
	
	public String getOId() {
		return getProperty("O_ID");
	}
	
	/**
	 * Extract the SDFNR property and take away the path
	 * @return filename of the SDFNR value with path
	 */
	public String getSdfnrNameNoPath() {
		String sdfnrName = getSdfnrName();
		if(!ASCUtil.isNullOrEmpty(sdfnrName)) {
			sdfnrName = sdfnrName.substring(sdfnrName.lastIndexOf('/') + 1);
		}
		return sdfnrName;
	}
	
	/**
	 *	Extract the base file name from an 'SDFNR' property.
	 *
	 * @param props Properties object possibly containing the SDFNR value
	 *
	 * @return The base file name of the SDFNR value, null if no such value
	 */
	public String getSdfnrName() {
		String temp = getSdfnr();
		
		if (temp == null) {
			return null;
		}
		
		temp = temp.replace('(', ' ');
		temp = temp.replace(')', ' ');
		temp = temp.trim();
		int index = temp.indexOf(',');
		String fName = temp.substring(0, index).trim();
		if (fName.length() > 0) {
			return fName;
		}
		// Empty content
		return null;
	}
	
	public int compareTo(Properties o)
	{
		ThfProperties tp = (ThfProperties)o;
		if (tp == null)
		{
			return 0;
		}
		String k1 = getProperty("TRANSID");
		String k2 = tp.getProperty("TRANSID");
		if ((k1 == null) || (k2 == null))
		{
			return 0;
		}
		int i1 = Integer.parseInt(k1);
		int i2 = Integer.parseInt(k2);
		return i1 - i2;
	}
}
